#pragma once

#ifndef _GUIBASE_H
#define _GUIBASE_H

#include <QGraphicsObject>
#include <qpoint.h>
#include <QtGui/qpainter.h>
#include <qpixmap.h>
#include <QtGui/qbitmap.h>
#include <QtCore/qmath.h>
#include <qtransform.h>
#include <qgraphicstransform.h>
#include "AnimationView.h"
#include <qrect.h>
//#include "GUIBaseInterface.h"
#include "GUIZValues.h"
#include "Agent.h"

class GUIBase : public QGraphicsObject//, public GUIBaseInterface
{
	Q_OBJECT
private:
	Agent* agent;

public:
	//FOR AGENT TESTS DO NOT TOUCH
	GUIBase(std::string) {}

	GUIBase(QGraphicsItem *parent = 0);
	GUIBase::GUIBase(std::string anim_path, QGraphicsItem * parent);
	~GUIBase();

	static AnimationView *factoryScene;

	virtual void setAgent(Agent*);
	void setGUIBaseAgent(Agent* agent);
	Agent* getGUIBaseAgent();

	void loadImage(const char*);
	void loadMultImages(std::string ig_path);
	void moveTo(qreal x, qreal y);
	void accelTo(qreal x, qreal y, qreal accel, qreal speedLimit);
	void move();
	void rotateTowards(qreal x, qreal y);
	void rotateTowardsOverTime(qreal x, qreal y, qreal startingX, qreal startingY);
	void rotateOverTime(qreal degrees, bool clockwise);
	void rotateStep();
	void scaleOverTime(qreal scale_factor);
	void moveInstantlyTo(qreal newX, qreal newY);
	void rotateInstantlyTo(qreal degrees);
	void scaleStep();
	void setMovementSpeed(qreal newMoveSpeed);
	void setRotationSpeed(qreal newRotSpeed);
	void setScaleSpeed(qreal newScaleSpeed);
	void setTransformToCenter();
	void setTransformToTopLeft();
	void advance(int phase);
	QRectF boundingRect() const;
	virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

	void debugPrint(char * msg);
	void debugPringObjData();
	
	bool originAtCenter; // True to make the origin of any GUI object the center of its bounding box.
	void setOriginCenter();
	void setOriginTopLeft();

	qreal distance(QPointF point1, QPointF point2);

	//bool isBroken();

//protected:	//THESE SHOULD NOT BE PUBLIC :|  -Keith
	QPointF destination;
	QPointF direction;
	qreal speed;
	qreal acceleration;
	qreal speedLimit;
	qreal rotationSpeed;
	qreal targetRotation;
	qreal imgScale;
	qreal scaleSpeed;
	qreal targetScale;
	bool moving;
	bool rotating;
	bool clockwiseRotation;
	bool scaling;
	bool movingInstantly;
	bool rotatingInstantly;
	bool broken;
	bool blackAndWhite;

public:
	virtual void doneMoving() {}
	virtual void doneMoving(qreal x, qreal y) {}

	virtual void doneRotating() {}
	virtual void doneRotating(qreal ang) {}

	virtual void doneScaling() {}
	virtual void doneScaling(qreal scale) {}

	virtual void DoBreak();
	virtual void DoFix();
	
	//QList<QGraphicTransform*> transforms;
	QTransform transTransform;
	QTransform rotTransform;
	QPixmap *img;
	struct Frame
	{
		GUIBase *factoryObject;
		Frame(GUIBase *object) { this->factoryObject = object; }
		QPixmap img[2];
		QRectF rect;
		QPixmap getImg() const { return img[(factoryObject->blackAndWhite || !factoryScene->isActive())]; }
	};
	int currentAnim;
	int currentFrame;
	
	QList< QList<Frame> > animations;


signals:
	void signalBeginMoving(qreal destX, qreal destY);
	void signalDoneMoving(qreal newX, qreal newY);
	void signalBeginAscending(qreal scaleInc, qreal scaleSpeed);
	void signalBeginDescending(qreal scaleInc, qreal scaleSpeed);
};
#endif